<?php
$this->pageTitle = 'Zoznam obratov';
?>
<div class="listing">
	<h3>Zoznam obratov</h3>
	<table class="list">
		<thead>
			<tr>
				<th class="identifier"><?php echo $this->Paginator->sort('id', 'ID'); ?></th>
				<th><?php echo $this->Paginator->sort('fk_offer_id', 'Ponuka'); ?></th>
				<th><?php echo $this->Paginator->sort('fk_demand_id', 'Dopyt'); ?></th>
				<th class="col100"><?php echo $this->Paginator->sort('commission', 'Provízia (€)'); ?></th>
				<th class="action"><?php echo 'Akcie'; ?></th>
			</tr>
		</thead>
		<tbody>
			<?php
			foreach ($transfers as $transfer):
			?>
			<tr>
				<td class="number">
					<?php echo $transfer['Transfer']['id']; ?>
				</td>
				<td>
					<?php
						if ($transfer['Transfer']['fk_offer_id']) {
							$offerParts = array();
							$offerParts[] = 'Popis: ' . html_entity_decode($this->Html->link($transfer['Offer']['html_description'], array('controller' => 'market', 'action' => 'view', $transfer['Transfer']['fk_offer_id'])));
							if ($transfer['Offer']['fk_client_id']) {
								$offerParts[] = 'Klient: ' . $this->Html->link(htmlspecialchars($transfer['Offer']['Client']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Offer']['fk_client_id']));
							}
							if ($transfer['Offer']['fk_tipster_id']) {
								$offerParts[] = 'Tiper: ' . $this->Html->link(htmlspecialchars($transfer['Offer']['Tipster']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Offer']['fk_tipster_id']));
							}
							if ($transfer['Offer']['fk_broker_id']) {
								$offerParts[] = 'Maklér: ' . $this->Html->link(htmlspecialchars($transfer['Offer']['Broker']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Offer']['fk_broker_id']));
							}
							echo implode('<br />', $offerParts);
						}
					?>
				</td>
				<td>
					<?php
						if ($transfer['Transfer']['fk_demand_id']) {
							$demandParts = array();
							$demandParts[] = 'Popis: ' . html_entity_decode($this->Html->link($transfer['Demand']['html_description'], array('controller' => 'market', 'action' => 'view', $transfer['Transfer']['fk_demand_id'])));
							if ($transfer['Demand']['fk_client_id']) {
								$demandParts[] = 'Klient: ' . $this->Html->link(htmlspecialchars($transfer['Demand']['Client']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Demand']['fk_client_id']));
							}
							if ($transfer['Demand']['fk_tipster_id']) {
								$demandParts[] = 'Tiper: ' . $this->Html->link(htmlspecialchars($transfer['Demand']['Tipster']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Demand']['fk_tipster_id']));
							}
							if ($transfer['Demand']['fk_broker_id']) {
								$demandParts[] = 'Maklér: ' . $this->Html->link(htmlspecialchars($transfer['Demand']['Broker']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Demand']['fk_broker_id']));
							}
							echo implode('<br />', $demandParts);
						}
					?>
				</td>
				<td class="number">
					<?php echo number_format($transfer['Transfer']['commission'], 2, ',', ' '); ?>
				</td>
				<td>
					<?php
						if (isset($userPermissions['transfer']['view'])) {
							echo $this->Html->link(__('View', true), array('action' => 'view', $transfer['Transfer']['id']), array('class' => 'show'));
						}
					?>
					<?php
						if (isset($userPermissions['transfer']['edit'])) {
							echo $this->Html->link(__('Uprav', true), array('action' => 'edit', $transfer['Transfer']['id']), array('class' => 'edit'));
						}
					?>
					<?php
						if (isset($userPermissions['transfer']['delete'])) {
							echo $this->Html->link(__('Delete', true), array('action' => 'delete', $transfer['Transfer']['id']), array('class' => 'delete'), __('Ste si istý, že chcete odstrániť záznam?', true));
						}
					?>
				</td>
			</tr>
			<?php endforeach; ?>
		</tbody>
	</table>

	<?php if ($this->Paginator->hasPage(2)): ?>
		<div class="pager">
			<?php echo $this->Paginator->prev('<< '.__('predchádzajúca', true), array(), null, array('class'=>'disabled')); ?>
			<?php echo $this->Paginator->numbers(); ?>
			<?php echo $this->Paginator->next(__('ďalšia', true).' >>', array(), null, array('class' => 'disabled')); ?>
		</div>
	<?php endif; ?>
</div>